//
//  NSMutableAttributedString+setAttributedText.m
//  QNReuseTool
//
//  Created by rsh on 2019/10/15.
//  Copyright © 2019年 rsh. All rights reserved.
//

#import "NSMutableAttributedString+setAttributedText.h"

//字符串是否为空
#define kStringIsEmpty(string) ([string isKindOfClass:[NSNull class]] || ([string isEqualToString:@"(null)"]) || [string isEqual:[NSNull null]] || ([string isEqualToString:@"<null>"]) ||string == nil || [string length] < 1 ? YES : NO )

@implementation NSMutableAttributedString (setAttributedText)

+ (NSMutableAttributedString *)qn_setAttributedWithMainText:(NSString *)mainText AttributedText:(NSString *)attributedText AttributedColor:(UIColor *)color AttributedFont:(CGFloat)font Attribute:(CGFloat)bute Andbold:(BOOL)isbold
{
    
    if (kStringIsEmpty(attributedText)) {
        attributedText = @"";
    }
    NSRange range = [mainText rangeOfString:attributedText];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:mainText];
    [string addAttribute:NSForegroundColorAttributeName value:color range:range];
    if (isbold == YES) {
        [string addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:font] range:range];
    }else{
       [string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:range];
    }
    [string addAttribute:NSExpansionAttributeName value:@(bute) range:range];
    
    return string;
}

//设置字体和颜色等
+ (NSMutableAttributedString *)qn_setAttributedWithMainText:(NSString *)mainText font:(UIFont *)font
{
//    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:mainText attributes:@{NSFontAttributeName: font,NSForegroundColorAttributeName: [UIColor colorWithRed:48/255.0 green:48/255.0 blue:48/255.0 alpha:1.0]}];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:mainText attributes:@{NSFontAttributeName: font}];
    return string;
}


@end
